/**
 * Xinfei.com Inc.
 * Copyright (c) 2004-2023 All Rights Reserved.
 */
package com.xinfei.techplayprod.biz.controller;

import com.xinfei.techplayprod.biz.common.TechplayConstants;
import com.xinfei.techplayprod.biz.log.DigestLogAnnotated;
import com.xinfei.techplayprod.biz.log.QueryDigestLog;
import com.xinfei.techplayprod.biz.rr.TeamQueryRequest;
import com.xinfei.techplayprod.biz.rr.TeamQueryResponse;
import com.xinfei.techplayprod.biz.rr.dto.TeamDto;
import com.xinfei.techplayprod.biz.service.TeamService;
import com.xinfei.techplayprod.biz.template.QueryCallBack;
import com.xinfei.techplayprod.biz.template.QueryTemplate;
import com.xinfei.techplayprod.biz.util.ParamCheckUtil;
import com.xinfei.techplayprod.itl.TechplayCoreFeinClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import static com.xinfei.techplayprod.biz.util.ParamCheckUtil.TEAM_CODE;

/**
 * 团队信息远程接口默认实现类<br/>
 *
 * @author Jinyan.Huang
 * @version $ TeamFacadeImpl, v 0.1 2023/8/28 12:20 Jinyan.Huang Exp $
 */
@RestController
@RequestMapping("/team")
public class TeamController {

    /**
     * 团队服务
     */
    @SuppressWarnings("SpringJavaAutowiredFieldsWarningInspection")
    @Autowired
    private TeamService teamService;

    @Autowired
    private TechplayCoreFeinClient techplayCoreFeignClient;

    @PostMapping("/querybycode")
    @DigestLogAnnotated(TechplayConstants.QUERY_DIGEST_LOG)
    public TeamQueryResponse queryByCode(@RequestBody TeamQueryRequest request) {

        final TeamQueryResponse result = new TeamQueryResponse();

        QueryTemplate.query(result, new QueryCallBack() {
            public void checkParameter() {
                ParamCheckUtil.checkParamNotNull(request, TEAM_CODE);
                ParamCheckUtil.checkParamNotBlank(request.getTeamCode(), TEAM_CODE);
            }

            public void doQuery() {
                TeamDto teamDto = teamService.query(request.getTeamCode());
                result.setData(teamDto);
            }

            public QueryDigestLog buildDigestLog() {
                return new QueryDigestLog(request);
            }

        });

        return result;
    }

    /**
     * 通过feign调techplaycore接口获取数据
     */
    @PostMapping("/queryByCodeFromCore")
    @DigestLogAnnotated(TechplayConstants.QUERY_DIGEST_LOG)
    public com.xinfei.techplayprod.itl.rr.TeamQueryResponse queryByCodeFromCore(@RequestBody com.xinfei.techplayprod.itl.rr.TeamQueryRequest request) {

        final com.xinfei.techplayprod.itl.rr.TeamQueryResponse result = new com.xinfei.techplayprod.itl.rr.TeamQueryResponse();

        QueryTemplate.query(result, new QueryCallBack() {
            public void checkParameter() {
                ParamCheckUtil.checkParamNotNull(request, TEAM_CODE);
                ParamCheckUtil.checkParamNotBlank(request.getTeamCode(), TEAM_CODE);
            }

            public void doQuery() {
                com.xinfei.techplayprod.itl.rr.TeamQueryResponse _result = techplayCoreFeignClient.QueryByCode(request);
                result.setData(_result.getData());
            }

            public QueryDigestLog buildDigestLog() {
                return new QueryDigestLog(request);
            }

        });

        return result;
    }

}
